import random

#第一题：输入两个数，求两个数的最大公约数

def firstText():
    while True:
        num1 = int(input("输入第一个数"))
        num2 = int(input("输入第二个数"))
        if num1 < num2:
            num1, num2 = num2, num1
        for a in range(num2, 1, -1):
            if num1 % a == 0 and num2 % a == 0:
                return a

        return 1

#(min最小值，max最大值）
#for a in range(min(num1, num2), 1, -1)):
#    if num1 % a == 0 and num2 % a == 0:
#        return a


#第二题：输出1-1/2+1/3-1/4+1/5-1/6......+1/99-1/100的结果(保留两位小数)

def secondText():
    s = 0
    for a in range(1, 101):
        if a % 2 == 0:
            a = -a ** -1
        else:
            a = a ** -1
        s += a
    print (round(s, 2))

#(round四舍五入)
#s = 1
#for a in range(2, 101):
#    if a % 2 == 0:
#        s -= 1 / a
#    else:
#        s += 1 / a
#print (round(s, 2))


#第三题：将八进制数转成十进制输出

def thirdText():
    num = int(input("输入一个八进制数:"))
    x = 1
    if num < 0:
        x = -1
        num *= -1

    n = 0
    s = 0
    while num > 0:
        s += num % 10 * 8 ** n
        n += 1
        num //= 10

    print ("十进制数是:", s * x)


#第四题：已知1900年一月一日是星期一，问今年有多少个黑色星期五,每月13号是星期五

#判断是否闰年
def isYear(year):
    return 1 if year % 400 == 0 or year % 4 == 0 and year % 100 != 0 else 0

#计算两个年之间天数
def countYearDays(sy, ey):
    days = 0
    while sy < ey:
        days += 365 + isYear(sy)
        sy += 1
    return days

#计算1月到指定月的天数
def countMonthDays(month, year):
    days = (month - 1) * 30 + month // 2
    if month == 9 or month == 11:
        days += 1
    if month > 2:
        days = days - 2 + isYear(year)
    return days

def blackFriday(year):
    days = countYearDays(1900, year) + 13
    for m in range(1, 13):
        if (days + countMonthDays(m, year)) % 7 == 5:
            print (year, "年", m, "月13号是黑色星期五！")


#第五题：张三从2000年1月1日开始过着三天打渔两天晒网的日子， \
#           输入年月日，判断他在打鱼还是晒网

def fish(year, month, day):
    d = (countYearDays(2000, year) + countMonthDays(month, year) + day) % 5
    s = "晒网" if  d == 4 or d == 0 else "打渔"
    print ("这天老铁在:", s)


#第六题：随机1-100之间的数，由用户输入猜测， \
#           用户输入的数打则提示大，小则提示小

def sixthText():
    num1 = random.randint(1, 100)
    while True:
        num2 = int(input("请输入一个数(100以内):"))
        if 0 < num2 < num1:
            print ("小了小了")
        elif 100 > num2 > num1:
            print ("大了大了")
        elif num1 == num2:
            print ("好吧你赢了")
            break
        else:
            print ("人人都玩不玩才怪")


#第七题：求1000以内的完数，完数：所有因子之和等于该本身

def seventhText():
    for num1 in range(1, 1001):
        s = 0
        for num2 in range(1, num1 + 1):
            if num1 % num2 == 0:
                s += num2
        if s == num1 * 2:
            print (num1)


#第八题：求1000以内的水仙花数（每一位的立方之和等于该本身）

def eighthText():
    for num in range(100, 1001):
        s = (num % 10) ** 3 + (num // 10 % 10) ** 3 + (num // 100 % 10) ** 3
        if s == num:
            print (num)

#for n1 in range(100, 1001):
#    s = 0
#    n2 = n1
#    while n2:
#        s += (n2 % 10) ** 3
#        n2 //= 10
#    if s == n1:
#        print (n1)


#第九题：打印三角形（输入边长直角三角形用一个循环）

def ninthText(n):
    for leng in range(n, 0, -1):
        print ("  " * (n - leng), " *" * leng)

#方法1
#n = 5
#for r in range(n):
#    for c in range(r):
#        print ('  ', end='')
#    for c in range(n - r):
#        print (' *', end='')
#    print ()

#方法2
#n = 5
#for r in range (n):
#    print ('  ' * r, ' *' * (n - r), sep='')

#方法3
#n = 5
#for i in range(n * n):
#    r, c = i // n, i % n
#    ch = '* ' if c >= r else '  '
#    print (ch, end='')
#    if c == n - 1:
#        print ()


#第十题：打印梯形

def tenthText(s, l):
    for leng in range(s, l + 1, 2):
        print (" " * (l + 1 - leng), " *" * leng)


#第十一题：用一个循环打印菱形，输入3打印

def eleventhText(n):
    for leng in range(1, n * 4 - 2, 2):
        if leng < n * 2 - 1:
            print (" " * (n * 2 - 1 - leng), " *" * leng)
        else:
            print (" " * (leng - n * 2 + 1),
                    " *" * (n * 4 - 3 - 2 * (leng // 2)))


#第十二题：实现菜单
while True:
    print ("欢迎光临！楼上雅座请！")
    print ("1:最大公约数")
    print ("2:1-1/2+1/3...-1/100结果")
    print ("3:八进制转十进制")
    print ("4:黑色星期五")
    print ("5:老铁与海")
    print ("6:猜数字")
    print ("7:1000内的完数")
    print ("8:水仙花数")
    print ("9:打印三角形")
    print ("10:打印梯形")
    print ("11:打印菱形")
    print ("0:退出")
    print ("*" * 50, "开始")
    num = int(input("请输入您的座位号："))
    print ()
    if num == 1:
       n = firstText()
       print (n)
    elif num == 2:
        secondText()
    elif num == 3:
        thirdText()
    elif num == 4:
        y = int(input("请输入您要查询的年份:"))
        blackFriday(n)
    elif num == 5:
        y = int(input("请输入您要查询的年:"))
        m = int(input("请输入您要查询的月:"))
        d = int(input("请输入您要查询的日:"))
        if y >= 1 and 1 <= m <=12 and 1 <= d <= 31:
            fish(y, m, d)
        else:
            print ("输入有误")
    elif num == 6:
        sixthText()
    elif num == 7:
        print ("1000内的完数有:")
        seventhText()
    elif num == 8:
        print ("1000内的水仙花数有:")
        eighthText()
    elif num == 9:
        n = int(input("请输入直角三角形边长:"))
        ninthText(n)
    elif num == 10:
        s = int(input("请输入梯形的上边长:"))
        l = int(input("请输入梯形的下边长:"))
        tenthText(s, l)
    elif num == 11:
        n = int(input("请输入菱形的边长:"))
        eleventhText(n)
    elif num == 0:
        print ("老板慢走！")
        break
    else:
        print ("很抱歉，没有该雅座号，请重新输入")
    print ("*" * 50, "结束")
